package com.hy.controller;

import com.hy.common.Result;
import com.hy.entity.WeeklyLike;
import com.hy.service.WeeklyLikeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;

@RestController
@RequestMapping("/weeklyLikes")
public class WeeklyLikeController {

    @Autowired
    private WeeklyLikeService weeklyLikeService;

    @GetMapping
    public Result<List<WeeklyLike>> getAllWeeklyLikes() {
        return Result.success(weeklyLikeService.list());
    }

    @GetMapping("/{id}")
    public Result<WeeklyLike> getWeeklyLike(@PathVariable Long id) {
        return Result.success(weeklyLikeService.getById(id));
    }

    @PostMapping
    public Result<Boolean> addWeeklyLike(@RequestBody WeeklyLike weeklyLike) {
        return Result.success(weeklyLikeService.save(weeklyLike));
    }

    @PutMapping("/{id}")
    public Result<Boolean> updateWeeklyLike(@PathVariable Integer id, @RequestBody WeeklyLike weeklyLike) {
        weeklyLike.setId(id);
        return Result.success(weeklyLikeService.updateById(weeklyLike));
    }

    @DeleteMapping("/{id}")
    public Result<Boolean> deleteWeeklyLike(@PathVariable Long id) {
        return Result.success(weeklyLikeService.removeById(id));
    }
} 